package com.ruoyi.web.controller.wbgame;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wbgame.domain.WbOption;
import com.ruoyi.wbgame.service.IWbOptionService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 选项Controller
 * 
 * @author guguofu
 * @date 2021-04-19
 */
@Controller
@RequestMapping("/wbgame/option")
public class WbOptionController extends BaseController
{
    private String prefix = "wbgame/option";

    @Autowired
    private IWbOptionService wbOptionService;

    @RequiresPermissions("wbgame:option:view")
    @GetMapping()
    public String option()
    {
        return prefix + "/option";
    }

    /**
     * 查询选项列表
     */
    @RequiresPermissions("wbgame:option:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WbOption wbOption)
    {
        startPage();
        List<WbOption> list = wbOptionService.selectWbOptionList(wbOption);
        return getDataTable(list);
    }

    /**
     * 导出选项列表
     */
    @RequiresPermissions("wbgame:option:export")
    @Log(title = "选项", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WbOption wbOption)
    {
        List<WbOption> list = wbOptionService.selectWbOptionList(wbOption);
        ExcelUtil<WbOption> util = new ExcelUtil<WbOption>(WbOption.class);
        return util.exportExcel(list, "option");
    }

    /**
     * 新增选项
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存选项
     */
    @RequiresPermissions("wbgame:option:add")
    @Log(title = "选项", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WbOption wbOption)
    {
        return toAjax(wbOptionService.insertWbOption(wbOption));
    }

    /**
     * 修改选项
     */
    @GetMapping("/edit/{optionId}")
    public String edit(@PathVariable("optionId") Long optionId, ModelMap mmap)
    {
        WbOption wbOption = wbOptionService.selectWbOptionById(optionId);
        mmap.put("wbOption", wbOption);
        return prefix + "/edit";
    }

    /**
     * 修改保存选项
     */
    @RequiresPermissions("wbgame:option:edit")
    @Log(title = "选项", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WbOption wbOption)
    {
        return toAjax(wbOptionService.updateWbOption(wbOption));
    }

    /**
     * 删除选项
     */
    @RequiresPermissions("wbgame:option:remove")
    @Log(title = "选项", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wbOptionService.deleteWbOptionByIds(ids));
    }
}
